IF ( LIBCITYGML_USE_XERCESC )
	FIND_PACKAGE( Xerces REQUIRED )
	ADD_DEFINITIONS( -DUSE_XERCESC )
	SET( LIBXML2_INCLUDE_DIR "" )
	SET( LIBXML2_LIBRARIES "" )
ENDIF( LIBCITYGML_USE_XERCESC )

IF( LIBCITYGML_USE_LIBXML2 )
	FIND_PACKAGE( LibXml2 REQUIRED )
	FIND_PACKAGE( Iconv REQUIRED )
	ADD_DEFINITIONS( -DUSE_LIBXML2 )
	ADD_DEFINITIONS( ${LIBXML2_DEFINITIONS} )
	SET( XERCESC_INCLUDE "" )
	SET( XERCESC_LIBRARY "" )
ENDIF( LIBCITYGML_USE_LIBXML2 )
	
IF( LIBCITYGML_USE_GDAL )
	FIND_PACKAGE( GDAL REQUIRED )
	ADD_DEFINITIONS( -DUSE_GDAL )
ELSE( LIBCITYGML_USE_GDAL )
	SET( GDAL_INCLUDE_DIR "" )
	SET( GDAL_LIBRARY "" )
ENDIF( LIBCITYGML_USE_GDAL )

FIND_PACKAGE( OpenGL REQUIRED )
#FIND_PACKAGE( GLU REQUIRED ) # deprecated, GLU is now found with FindOpenGL

IF( COMMAND cmake_policy )
	cmake_policy( SET CMP0003 NEW )
ENDIF( COMMAND cmake_policy )
	
ADD_DEFINITIONS( -DCITYGML_LIBRARY )

ADD_DEFINITIONS( -DLIBCITYGML_BUILD )

IF( LIBCITYGML_STATIC )
	ADD_DEFINITIONS( -DLIBCITYGML_STATIC )
ENDIF( LIBCITYGML_STATIC )

IF( LIBCITYGML_DYNAMIC )
	ADD_DEFINITIONS( -DLIBCITYGML_DYNAMIC )
ENDIF( LIBCITYGML_DYNAMIC )

IF( MSVC AND LIBCITYGML_STATIC_CRT )
	#We statically link to reduce dependancies
	FOREACH( flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO )
		IF( ${flag_var} MATCHES "/MD" )
			string( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
		ENDIF( ${flag_var} MATCHES "/MD" )
		IF( ${flag_var} MATCHES "/MDd" )
			string( REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}" )
		ENDIF( ${flag_var} MATCHES "/MDd" )
	ENDFOREACH( flag_var )
ENDIF( MSVC AND LIBCITYGML_STATIC_CRT )

SET( LIB_NAME citygml )

INCLUDE_DIRECTORIES( ../include ${XERCESC_INCLUDE} ${LIBXML2_INCLUDE_DIR} ${ICONV_INCLUDE_DIR} ${GLU_INCLUDE_PATH} ${GDAL_INCLUDE_DIR} )

SET( LIB_SRCS
	citymodel.cpp
	parser.cpp
	parserxercesc.cpp
	parserlibxml2.cpp
	tesselator.cpp
)

SET( LIB_PUBLIC_HEADERS
	../include/citygml.h
	../include/vecs.h
	./parser.h
	./transform.h
	./tesselator.h
	./utils.h
)

ADD_LIBRARY( ${LIB_NAME} ${LIBCITYGML_USER_DEFINED_DYNAMIC_OR_STATIC} ${LIB_SRCS} ${LIB_PUBLIC_HEADERS} )

TARGET_LINK_LIBRARIES( ${LIB_NAME} ${XERCESC_LIBRARIES} ${LIBXML2_LIBRARIES} ${OPENGL_LIBRARIES} ${GDAL_LIBRARY} )

# IF( MSVC_IDE )
	# SET_TARGET_PROPERTIES( ${LIB_NAME} PROPERTIES PREFIX "../" )
# ENDIF( MSVC_IDE )

INCLUDE(ModuleInstall OPTIONAL)
